package com.ruoyi.web.domain.dto;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import java.math.BigDecimal;

/**
 * 微信支付请求实体
 * 
 * @author ruoyi
 */
public class WxPayRequest {
    
    /** 商品描述 */
    @NotBlank(message = "商品描述不能为空")
    private String description;
    
    /** 商户订单号 */
    @NotBlank(message = "商户订单号不能为空")
    private String outTradeNo;
    
    /** 订单金额（分） */
    @NotNull(message = "订单金额不能为空")
    @Positive(message = "订单金额必须大于0")
    private Integer totalAmount;
    
    /** 用户openid */
    @NotBlank(message = "用户openid不能为空")
    private String openid;
    
    /** 组织ID（多商户场景） */
    @NotBlank(message = "组织ID不能为空")
    private String orgId;

    /** 微信应用ID（wechatAppId） */
    @NotBlank(message = "微信应用ID不能为空")
    private String wechatAppId;
    
    /** 附加数据 */
    private String attach;
    
    /** 订单优惠标记 */
    private String goodsTag;
    
    /** 订单失效时间（分钟，默认30分钟） */
    private Integer timeExpire = 30;
    
    public WxPayRequest() {
    }
    
    public WxPayRequest(String description, String outTradeNo, Integer totalAmount, String openid) {
        this.description = description;
        this.outTradeNo = outTradeNo;
        this.totalAmount = totalAmount;
        this.openid = openid;
    }
    
    /**
     * 将元转换为分
     */
    public static Integer yuanToFen(BigDecimal yuan) {
        if (yuan == null) {
            return 0;
        }
        return yuan.multiply(new BigDecimal("100")).intValue();
    }
    
    /**
     * 将分转换为元
     */
    public static BigDecimal fenToYuan(Integer fen) {
        if (fen == null) {
            return BigDecimal.ZERO;
        }
        return new BigDecimal(fen).divide(new BigDecimal("100"), 2, BigDecimal.ROUND_HALF_UP);
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    public String getOutTradeNo() {
        return outTradeNo;
    }
    
    public void setOutTradeNo(String outTradeNo) {
        this.outTradeNo = outTradeNo;
    }
    
    public Integer getTotalAmount() {
        return totalAmount;
    }
    
    public void setTotalAmount(Integer totalAmount) {
        this.totalAmount = totalAmount;
    }
    
    public String getOpenid() {
        return openid;
    }
    
    public void setOpenid(String openid) {
        this.openid = openid;
    }
    
    public String getAttach() {
        return attach;
    }
    
    public void setAttach(String attach) {
        this.attach = attach;
    }
    
    public String getGoodsTag() {
        return goodsTag;
    }
    
    public void setGoodsTag(String goodsTag) {
        this.goodsTag = goodsTag;
    }
    
    public Integer getTimeExpire() {
        return timeExpire;
    }
    
    public void setTimeExpire(Integer timeExpire) {
        this.timeExpire = timeExpire;
    }
    
    public String getOrgId() {
        return orgId;
    }

    public void setOrgId(String orgId) {
        this.orgId = orgId;
    }

    public String getWechatAppId() {
        return wechatAppId;
    }

    public void setWechatAppId(String wechatAppId) {
        this.wechatAppId = wechatAppId;
    }
    
    @Override
    public String toString() {
        return "WxPayRequest{" +
                "outTradeNo='" + outTradeNo + '\'' +
                ", totalAmount=" + totalAmount +
                ", openid='" + openid + '\'' +
                ", orgId='" + orgId + '\'' +
                ", wechatAppId='" + wechatAppId + '\'' +
                ", description='" + description + '\'' +
                ", attach='" + attach + '\'' +
                ", goodsTag='" + goodsTag + '\'' +
                ", timeExpire=" + timeExpire +
                '}';
    }
}
